package com.v1.web.listener;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.ContextLoaderListener;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.v1.util.Toolkit;

public class StartupListener extends ContextLoaderListener {
	/**
     */
	private static final Log log = LogFactory.getLog(StartupListener.class);

	/**
	 * @param event
	 *            event
	 */
	public final void contextInitialized(ServletContextEvent event) {
		log.debug("initializing context...");

		// call Spring's context ContextLoaderListener to initialize
		// all the context files specified in web.xml
		super.contextInitialized(event);

		ServletContext context = event.getServletContext();

		ApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(context);

		Toolkit toolkit = Toolkit.getInstance();
		toolkit.setApplicationContext(ctx);
	}
}
